﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Public.Ocean.Petrel.Extensions.Services;

namespace Public.Ocean.Petrel.Extensions.UnitTest
{
    [TestClass]
    public class ServiceWrapperTest
    {
        [TestMethod]
        public void TestEmptyWrapper()
        {
            string item = "Item";

            var wrappedItem = new PetrelServiceWrapper(new DelegateLocator(), item);
            
            Assert.AreEqual(item.ToString(), wrappedItem.Presentation.Text);
            Assert.AreEqual(string.Empty, wrappedItem.Settings.Text);
            Assert.AreEqual(0, wrappedItem.History.History.Count());

            var wrappedNull = new PetrelServiceWrapper(new DelegateLocator(), null);
            Assert.AreEqual("NULL", wrappedNull.Presentation.Text);
            Assert.AreEqual(0, wrappedNull.History.History.Count());
        }

        [TestMethod]
        public void TestEnumerate()
        {
            string item = "Item";
            var wrappedItem = new PetrelServiceWrapper(new DelegateLocator(type => new SelfObservableEnumeratorFactory()), item);
            var enumerator = wrappedItem.EnumerateRecursive().GetEnumerator();
            Assert.IsTrue(enumerator.MoveNext());
            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(item, enumerator.Current);

            var typedEnumerator = wrappedItem.EnumerateRecursive<string>().GetEnumerator();
            Assert.IsTrue(typedEnumerator.MoveNext());
            Assert.AreEqual<string>(item, typedEnumerator.Current);

            var typedPredicateEnumerator = wrappedItem.EnumerateRecursive<string>(i => i.Contains("I")).GetEnumerator();
            Assert.IsTrue(typedPredicateEnumerator.MoveNext());
        }
    }
}